/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simulation;

import persistence.DataWriter;

/**
 *
 * @author Danielondon
 */
public class MarketFactory {
    
    public static String EXTENSION_MARKET = ".csv_m";
    
    public static void generateMarket(String filename, double startPrice, double endPrice, int slotCount, boolean dualPriceModel, double startSecondPrice, double endSecondPrice) throws Exception{
        DataWriter dataWriter = new DataWriter(filename+EXTENSION_MARKET, true);
        int nightCount = (int)(slotCount * startSecondPrice);
        int dayCount = (int)(slotCount * endSecondPrice);
        if (dualPriceModel){
            if (endSecondPrice < startSecondPrice)
                throw new Exception ("The end of second price has to be greater than the start");
            
            for (int i = 0; i < slotCount; i++){
                // Valley Time
                if (i < nightCount || i >= dayCount){
                    dataWriter.write(startPrice + "");
                } else {
                  // Peak Time  
                    dataWriter.write(endPrice + "");
                }
                    
            }           
        } else {
            double difference = endPrice - startPrice;
            double change = difference / (double)(slotCount-1);
            for (int i = 0; i < slotCount; i++){
                dataWriter.write(startPrice + (change *i) + "");                    
            }
        }
    }
}
